home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4638 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.2 KB

  1. Path: news.uni-jena.de!news
  2. From: mkt@isun04.inf.uni-jena.de (Tilo Koerbs)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: novice question on copy constru
  5. Date: 31 Jan 1996 13:13:36 GMT
  6. Organization: Lehrstuhl fuer Rechnerarchitektur- und kommunikation, FSU Jena
  7. Message-ID: <4enpu0$qlr@fsuj01.rz.uni-jena.de>
  8. References: <4efpie$jsq@news.ust.hk>
  9. Reply-To: mkt@isun04.inf.uni-jena.de
  10. NNTP-Posting-Host: isun07.inf.uni-jena.de
  11.  
  12. >To the question:
  13. >>I don't understand why one should create a copy constructor. Doesn't the
  14. >>computer will do the job for you when pass arguments by value? Thanks
  15.  
  16. You don't need to write a copy constructor. It is always created
  17. by the compiler. (In contrast to the default constructor,
  18. which is only created if no constructor is written by the user.)
  19.  
  20. The only problem is: If your class contains pointers (better:
  21. dynamically allocated data). In this case You need to write
  22. the constructor. The compiler generates only bitwise copies. And this
  23. is not what You want for pointers. They will point to the data
  24. belonging to the object You copy from.
  25.  
  26. Again: If You don't have pointers in your class You probably never need to
  27. write a copy constructor by hand.
  28.  
  29.  
  30.